home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / PictureItem.C < prev    next >
C/C++ Source or Header  |  1992-05-05  |  1KB  |  78 lines

  1. #ifdef __GNUG__
  2. #pragma implementation
  3. #endif
  4.  
  5. #include "PictureItem.h"
  6.  
  7. #include "Class.h"
  8. #include "Picture.h"
  9.  
  10. //---- PictureItem -------------------------------------------------------------
  11.  
  12. NewMetaImpl(PictureItem,VObject, (TP(pic), T(base), TB(deletePicture)));
  13.  
  14. PictureItem::PictureItem(Picture *b, int bs, bool freeold)
  15. {
  16.     deletePicture= freeold;
  17.     base= bs;
  18.     pic= b;
  19. }
  20.  
  21. PictureItem::PictureItem(int id, Picture *b, int bs, bool freeold) : VObject(id)
  22. {
  23.     deletePicture= freeold;
  24.     base= bs;
  25.     pic= b;
  26. }
  27.  
  28. PictureItem::~PictureItem()
  29. {
  30.     if (deletePicture)
  31.     SafeDelete(pic);
  32. }
  33.  
  34. void PictureItem::SetPicture(Picture *p, bool redraw)
  35. {
  36.     if (deletePicture && pic)
  37.     delete pic;
  38.     deletePicture= FALSE;
  39.     pic= p;
  40.     SetContentRect(Rectangle(GetOrigin(), GetMinSize().extent), redraw);
  41. }
  42.  
  43. Metric PictureItem::GetMinSize()
  44. {
  45.     if (pic)
  46.     return Metric(pic->Size(), base ? base : pic->Size().y);
  47.     return VObject::GetMinSize();
  48. }
  49.  
  50. void PictureItem::Draw(Rectangle r)
  51. {
  52.     GrEraseRect(r);
  53.     if (pic)
  54.     GrShowPicture(contentRect, pic);
  55. }
  56.  
  57. void PictureItem::DoObserve(int, int part, void*, Object *op)
  58. {
  59.     if (op == pic && part != cPartSenderDied)
  60.     ForceRedraw();
  61. }
  62.  
  63. OStream& PictureItem::PrintOn (OStream &s)
  64. {
  65.     VObject::PrintOn(s);
  66.     return s << pic SP << base SP;
  67. }
  68.  
  69. IStream& PictureItem::ReadFrom(IStream &s)
  70. {
  71.     if (deletePicture)
  72.     SafeDelete(pic);
  73.     deletePicture= TRUE;
  74.     VObject::ReadFrom(s);
  75.     return s >> pic >> base;
  76. }
  77.  
  78.